package edu.xja.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import edu.xja.dao.AcademyDao;
import edu.xja.dao.AdminDao;
import edu.xja.entity.Academy;
import edu.xja.service.AcademyService;
import edu.xja.util.SqlSessionFactoryUtil;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;

import java.util.List;

public class AcademyServiceImpl implements AcademyService {
    private AcademyDao academyDao;
    {
        SqlSessionFactory sqlSessionFactory= SqlSessionFactoryUtil.getSqlSessionFactory();
        SqlSession sqlSession=sqlSessionFactory.openSession(true);
        academyDao=sqlSession.getMapper(AcademyDao.class);
    }
    public int add(Academy academy) {
        return academyDao.add(academy);
    }

    public int updateById(Academy academy) {
        return academyDao.updateById(academy);
    }

    public int delete(Academy academy){
        return academyDao.delete(academy);
    }

    public List<Academy> findAll() {
        return academyDao.findAll();
    }

    @Override
    public Academy getById(Integer id) {
        return academyDao.getById(id);
    }

    public PageInfo<Academy> search(int pageNum,int pageSize) {
        PageHelper.startPage(pageNum,pageSize);
        List<Academy> academyList=academyDao.findAll();
        PageInfo<Academy> academyPageInfo=new PageInfo<Academy>(academyList);
        return academyPageInfo;
    }
}
